package com.elloe.lesson;

import java.util.Scanner;

/**
 * @author ElloeStudy(Sifa Zhang)
 * @create 2021-11-17 16:15
 * To: 真常应物，真常得性，常清常静，常清静矣
 */
public class Demo2 {
//    测试 O(n) o(n^2) O(nlogn)的运行时间
    public static void main(String[] args) {
        long n;
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入N： ");
        n = Long.parseLong(scanner.nextLine().trim());
        long startTime1 = System.currentTimeMillis();
        fun1(n);
        long endTime1 = System.currentTimeMillis();
        System.out.println("程序1运行的时间： "+ (endTime1-startTime1)+" ms");

        long startTime2 = System.currentTimeMillis();
        fun2(n);
        long endTime2 = System.currentTimeMillis();
        System.out.println("程序2运行的时间： "+ (endTime2-startTime2)+" ms");

        long startTime3 = System.currentTimeMillis();
        fun3(n);
        long endTime3 = System.currentTimeMillis();
        System.out.println("程序3运行的时间： "+ (endTime3-startTime3)+" ms"); // 测试程序运行的时间
    }

    /**
     * java访问修饰符有4个
     * public
     * protected
     * default
     * private
     * 不写默认是default
     * @param n
     */
     public static void fun1(long n){
        long k = 0;
        for (long i = 0; i < n; i++) {
            k++;
            
        }
    }

    public static void fun2(long n){
        long k = 0;
        for (long i=0;i<n;i++){
            for (long j=0;j<n;j++){
                 k++;
            }
        }
    }

    public static void fun3(long n){
        long k =0;
        for (long i=0;i<n;i++){
            for (long j=1;j<n;j=j*2){
                k++;
            }
        }
    }


}
